package com.consumer0.demo;


import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectionConfig {
    public static Connection getConnection() throws IOException, TimeoutException {
        //    1.创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
//    在工厂对象中设置MQ的连接信息（(ip,port,virtualhost,username,password)
        factory.setHost("10.3.7.109");
        factory.setPort(5672);
        factory.setVirtualHost("/test_virtual_host");
        factory.setUsername("root");
        factory.setPassword("QweHxj@qjty");
        //通过工厂对象获取mq的连接
        Connection connection = factory.newConnection();
        return connection;

    }
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = getConnection();
        System.out.println(connection);
    }
}
